package com.kara.woodAgent.web.user.controller;

import cn.hutool.core.util.StrUtil;
import com.kara.woodAgent.common.exception.BizException;
import com.kara.woodAgent.web.user.model.request.LoginRequest;
import com.kara.woodAgent.web.user.model.request.RegisterRequest;
import com.kara.woodAgent.web.user.model.vo.LoginVo;
import com.kara.woodAgent.web.user.service.WgUserService;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author tzy
 * @version 1.0
 * @project wood_agent
 * @description
 * @date 2025/6/6 15:32:15
 */
@RestController("/user")
public class UserController {

    @Autowired
    private WgUserService wgUserService;

    @PostMapping("/login")
    public LoginVo login(@Valid @RequestBody LoginRequest loginRequest) {

        String email = loginRequest.getEmail();
        String username = loginRequest.getUsername();
        if (StrUtil.isBlank(email) || StrUtil.isBlank(username)) {
            throw new BizException("邮箱或用户名不能为空");
        }
        return wgUserService.login(loginRequest);
    }


    @PostMapping("/register")
    public void register(@Valid @RequestBody RegisterRequest registerRequest) {
        // 检查必要的注册信息是否为空
        // 调用服务层的注册方法
        wgUserService.register(registerRequest);
    }
}

